Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
The 'deepcopy' npm package is used to create deep copies of JavaScript objects. This means that it recursively copies all nested objects and arrays, ensuring that the new object is completely independent of the original.
Deep Copy of Objects
This feature allows you to create a deep copy of an object, ensuring that nested objects are also copied.
const deepcopy = require('deepcopy');
const original = { a: 1, b: { c: 2 } };
const copy = deepcopy(original);
console.log(copy); // { a: 1, b: { c: 2 } }
Deep Copy of Arrays
This feature allows you to create a deep copy of an array, ensuring that nested arrays and objects are also copied.
const deepcopy = require('deepcopy');
const original = [1, [2, 3], { a: 4 }];
const copy = deepcopy(original);
console.log(copy); // [1, [2, 3], { a: 4 }]
Handling Circular References
This feature allows you to handle circular references in objects, ensuring that the deep copy process does not result in an infinite loop.
const deepcopy = require('deepcopy');
const original = { a: 1 };
original.b = original;
const copy = deepcopy(original);
console.log(copy); // { a: 1, b: [Circular] }
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes a `cloneDeep` function that performs deep copying similar to `deepcopy`. However, Lodash offers many additional utilities beyond deep copying.
The 'rfdc' (Really Fast Deep Clone) package is designed for performance and provides a very fast way to deep clone objects. It is similar to `deepcopy` in functionality but is optimized for speed.
The 'clone-deep' package is another utility for deep cloning objects and arrays. It is similar to `deepcopy` but offers additional options for customizing the cloning process.
deep copy for any data
$ npm install deepcopy
$ bower install deepcopy
var deepcopy = require('deepcopy');
<script src="deepcopy.min.js"></script>
define deepcopy
by define()
if using AMD loader.
otherwise deepcopy
export to global.
var data, shallow, deep;
data = {
objects: {
array: [
null, undefined, new Date, /deepcopy/ig
],
object: {
number: NaN,
string: 'A',
boolean: true
},
to: null
}
};
// circular reference
data.objects.to = data;
// shallow copy and deep copy
shallow = data;
deep = deepcopy(data);
// remove entry
delete data.objects;
// results
console.log(data);
// {}
console.log(shallow);
// {}
console.log(require('util').inspect(deep, { depth: null }));
// { objects:
// { array:
// [ null,
// undefined,
// Sat Jan 10 2015 03:18:32 GMT+0900 (JST),
// /deepcopy/gi ],
// object: { number: NaN, string: 'A', boolean: true },
// to: [Circular] } }
var data, deep;
data = { object: {} };
data.object[Symbol.for('sym')] = 123;
deep = deepcopy(data);
delete data.object;
console.log(data.object);
// undefined
console.log(deep.object[Symbol.for('sym')]);
// 123
value
*
- copy target valuereturn
*
- deep copied valuereturn deep copied value.
supported types are below:
$ npm install
$ npm test
$ npm install
$ npm run bower
$ npm run testem
The MIT license. Please see LICENSE file.
0.5.0 / 2015-04-11
FAQs
deep copy data
The npm package deepcopy receives a total of 156,503 weekly downloads. As such, deepcopy popularity was classified as popular.
We found that deepcopy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.